package user

import (
	"context"
	"github.com/jinzhu/copier"
	"go.mongodb.org/mongo-driver/bson/primitive"
	model "large-model-platform-backend/mongo"

	"large-model-platform-backend/internal/svc"
	"large-model-platform-backend/internal/types"

	"github.com/zeromicro/go-zero/core/logx"
)

type UpdateLogic struct {
	logx.Logger
	ctx    context.Context
	svcCtx *svc.ServiceContext
}

func NewUpdateLogic(ctx context.Context, svcCtx *svc.ServiceContext) *UpdateLogic {
	return &UpdateLogic{
		Logger: logx.WithContext(ctx),
		ctx:    ctx,
		svcCtx: svcCtx,
	}
}

func (l *UpdateLogic) Update(req *types.UserUpdateReq) (resp *types.BooleanResp, err error) {
	model1 := l.svcCtx.UserModel
	objectID, err := primitive.ObjectIDFromHex(req.ID)
	common := model.UserCommon{}
	copier.Copy(&common, req)
	user := model.User{
		ID:         objectID,
		UserCommon: common,
	}
	// todo 有问题，聊天内容会被清空 后续改
	_, err = model1.Update(l.ctx, &user)
	return &types.BooleanResp{
		Result: types.Result{Code: 200},
		Data:   true,
	}, nil
}
